Why you should use python -m pip
What is python -m pip?
/usr/bin/python3.7 -m pip means you are executing pip for your interpreter located at /usr/bin/python3.7.
環境変数PATHの話
Why use python -m pip over pip/pip3?
例:python3.7とpython3.8があるケース
what the last copy of pip was written to /usr/local/bin/pip
when you use python -m pip with python being the specific interpreter you want to use, all of the above ambiguity is gone.
曖昧さがなく、すべて制御している
Basically because pip.exe is considered running when you do pip install --upgrade pip, Windows won't let you overwrite pip.exe. But if you do python -m pip install --upgrade pip you avoid that issue as it's python.exe that's running, not pip.exe.
Windowsで好まれる事情
What about when I am in an activated environment?
Windowsでpipをupgradeする方法は仮想環境でも該当
I would say you should use python -m pip as it works regardless of the situation.
仮想環境を有効にし忘れるミスを回避できる
ベストプラクティスを他の人に伝えられる
Personally, any tool that I use whose execution relies on which interpreter it is run with I always use -m, activated environment or not, in order to be very purposefully and explicit in what Python interpreter I want to be used/affected.
ALWAYS use an environment! Don't install into your global interpreter!
PIP_REQUIRE_VIRTUALENVを1にしておく
コマンドラインで0で上書きできる (emergency escape hatch)
If you need to install a tool
If you need an environment for your project (and you don't use conda)
python -m venv
.venv/bin/python works just as well as activating the environment and typing python.
pyvenvコマンドに言及
If you are a conda user
There's always containers
As long as you are not installing into the system Python of the container you should be free to do a global install to keep your container simple and straight-forward.
同様のエントリはクジラ飛行机さんの連載で見かけた覚えあり